<template>
	<view class="main">
		<view class="xc" style="background-color: #FFF;margin-bottom: 10px;">
			<view class="title-xc" style="padding: 10px;font-size: 16px;font-weight: 800;">
				巡查详情
			</view>
			<div><u-line></u-line></div>
			<view class="content-xc" style="padding: 10px 10px 0px 10px;">
				<view class="c-xc-c" v-for="(item,index) in list" :key="index" style="display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 10px;">
					<view class="cleft">
						{{item.name}}
					</view>
					<view class="cright" :style="getStyleByZgqx(item)">
						{{item.value}}
					</view>
				</view>
			</view>
			<view class="cleft" style="padding: 0px 10px 10px 10px;" v-show="xcImageList.length!=0">
				现场图片
			</view>
			<view class="images" v-for="(item,index) in xcImageList" :key="index" style="padding: 0px 10px 10px 10px;">
				<img :src="item.url" style="width: 100%;"/>
			</view>
		</view>
		<view v-if="data.fkztn=='已反馈'" class="fk" style="background-color: #FFF;margin-top: 10px;">
			<view class="title-xc" style="padding: 10px;font-size: 16px;font-weight: 800;">
				反馈详情
			</view>
			<div><u-line></u-line></div>
			<view class="content-fk" style="padding: 10px 10px 0px 10px;">
				<view class="fka" style="display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 10px;">
					<view class="cleft">
						反馈状态
					</view>
					<view class="cright">
						{{data.fkztn}}
					</view>
				</view>
				<view class="fka" style="display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 10px;">
					<view class="cleft">
						反馈内容
					</view>
					<view class="cright">
						{{data.fknr}}
					</view>
				</view>
			</view>
			<view class="cleft" style="padding: 0px 10px 10px 10px;"  v-show="fkImageList.length!=0">
				现场图片
			</view>
			<view class="images" v-for="(item,index) in fkImageList" :key="index" style="padding: 0px 10px 10px 10px;">
				<img :src="item.url" style="width: 100%;"/>
			</view>
		</view>
		<view class="th" style="background-color: #FFF;" v-show="backStatus=='1'">
			<view class="title-xc" style="padding: 10px;font-size: 16px;font-weight: 800;">
				退回详情
			</view>
			<div><u-line></u-line></div>
			<view class="time" style="padding: 0px 10px;margin-top: 10px;display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 10px;">
				<view class="cleft">
					{{'退回时间'}}
				</view>
				<view class="cright">
					{{backTime}}
				</view>
			</view>
			<view class="time" style="padding: 0px 10px 10px 10px;margin-top: 10px;display: flex;align-items: flex-start;justify-content: space-between;margin-bottom: 10px;">
				<view class="cleft">
					{{'退回原因'}}
				</view>
				<view class="cright">
					{{backContent}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { findPro,getDateDic } from '@/common/api.js'
	export default{
		onLoad: function(option){
			this.id = option.id
			
			uni.setNavigationBarTitle({
			    title: option.title
			});
		},
		async onShow() {
			let that = this
			await that.getDic()
			await that.getDetail(that.id)
		},
		data(){
			return{
				/* 字典 */
				dic:{
					status:'Enabled',
					type:'PROJECT_ZGZT'
				},
				dicList:[],
				data:'',
				list:[
					{name:'意见单编号',code:'yjbh',value:''},
					{name:'项目名称',code:'xmmc',value:''},
					{name:'整改状态',code:'zgztn',value:''},
					{name:'建设单位',code:'jsdw',value:''},
					{name:'监理单位',code:'jldw',value:''},
					{name:'施工单位',code:'sgdw',value:''},
					{name:'设计单位',code:'sjdw',value:''},
					{name:'责任部门',code:'trbm',value:''},
					{name:'项目进度情况',code:'xmjdms',value:''},
					{name:'指导单位',code:'zddw',value:''},
					{name:'指导人员',code:'zdry',value:''},
					{name:'指导时间',code:'zdsj',value:''},
					{name:'存在问题',code:'czwt',value:''},
					{name:'指导意见',code:'zdyj',value:''},
					{name:'整改要求',code:'zgyq',value:''},
					{name:'整改期限',code:'zgqx',value:''}
				],
				xcImageList:[],
				fkImageList:[],
				backTime:'',
				backContent:'',
				backStatus:'',
				sfzgwc:null,
				zgqxTxt:'',
				id:'',
			}
		},
		methods:{
			getDic(){
				getDateDic(this.dic).then(res => {
					this.dicList = res
				})
			},
			getStyleByZgqx(item){
				if(item.code == 'zgqx'){
					if(!(this.sfzgwc==1 || this.sfzgwc=='1')){
						if((this.sfzgwc == 0 || this.sfzgwc == '0' || this.sfzgwc==null) && this.zgqxTxt!=''){
							let datezero = this.zgqxTxt
							let tomorrow = new Date();
							tomorrow.setDate(tomorrow.getDate() + 1);
							tomorrow.setHours(0, 0, 0, 0);
							let tomorrowStr = tomorrow.getFullYear() + '-' + 
											  (tomorrow.getMonth() + 1).toString().padStart(2, '0') + '-' + 
											  tomorrow.getDate().toString().padStart(2, '0');
							if (datezero <= tomorrowStr) {
								return {'color':'#fa3534'}
							}
						}
					}
				}
			},
			getDetail(id){
				findPro({id:id}).then(res => {
					let data = res
					this.backStatus = data.sfth
					this.backContent = data.thyy
					let back = new Date(data.thsj)
					this.backTime = back.getFullYear() + '-' +
					    ('0' + (back.getMonth()+1)).slice(-2) + '-' +
					    ('0' + back.getDate()).slice(-2) + ' ' +
					    ('0' + back.getHours()).slice(-2) + ':' +
					    ('0' + back.getMinutes()).slice(-2) + ':' +
					    ('0' + back.getSeconds()).slice(-2)
					
					const dateTemp = this.dicList.find(zoo => zoo.code === data.zgzt)
					if (dateTemp) {data.zgztn = dateTemp.name}
					if(data.fkzt==1){
						data.fkztn = '已反馈'
						this.fkImageList = data.fkfjList
					}else{
						data.fkztn = '未反馈'
					}
					let dateStr = data.zdsj
					let date = new Date(dateStr)
					let formattedDate = date.getFullYear() + '-' +
					    ('0' + (date.getMonth()+1)).slice(-2) + '-' +
					    ('0' + date.getDate()).slice(-2) + ' ' +
					    ('0' + date.getHours()).slice(-2) + ':' +
					    ('0' + date.getMinutes()).slice(-2) + ':' +
					    ('0' + date.getSeconds()).slice(-2)
					data.zdsj = formattedDate
					
					if(data.zgqx != null && data.zgqx != ''){
						let dateStrX = data.zgqx
						let dateX = new Date(dateStrX)
						let formattedDateX = dateX.getFullYear() + '-' +
						    ('0' + (dateX.getMonth()+1)).slice(-2) + '-' +
						    ('0' + dateX.getDate()).slice(-2)
						data.zgqx = formattedDateX
						this.zgqxTxt = formattedDateX
					}
					this.sfzgwc = data.sfzgwc ? data.sfzgwc : null
					/* 巡查部分 */
					for(let item of this.list) {
					    item.value = data[item.code]
					}
					this.xcImageList = data.xcfjList
					this.data = data
				})
			}
		}
	}
</script>

<style scoped>
	.cleft{
		width: 100px;
		font-family: 'PingFangSC-Regular';
		font-size: 14px;
		color: #999999;
		font-weight: 400;
	}
	.cright{
		flex:1;
		font-family: 'PingFangSC-Regular';
		font-size: 14px;
		color: #212121;
		text-align: right;
		font-weight: 400;
	}
</style>